/**
 * DataTypeConverter.java
 * 2012-3-26 下午08:27:48
 */
package xgenerator.converter;

import xgenerator.constants.SqlDataTypes;
import xgenerator.constants.JavaTypes;
import xgenerator.constants.PropertyTypes;

/**
 * <p>
 * Title:类的中文名
 * </p>
 * <p>
 * Description:具体功能见各方法描述
 * </p>
 * <p>
 * Copyright:Copyright (c) 2012
 * </p>
 * 
 * @author <a href="mailto:lishushan@gmail.com">liss</a>
 * @version 1.0
 */
public class JavaTypeConverter implements PropertyTypeConverter, SqlDataTypes {

	public static final PropertyTypes javaTypes = new JavaTypes();
	
	private boolean wrapperMode;
	
	public JavaTypeConverter() {
		this.wrapperMode = false;
	}
	
	public JavaTypeConverter(boolean wrapperMode) {
		this.wrapperMode = wrapperMode;
	}
	
	public String convert(String sqlType) {
		String javaType = "";
		
		if(wrapperMode) {
			if(BIT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.booleanWrapper();
			} else if(TINYINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteWrapper();
			} else if(SMALLINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.shortWrapper();
			} else if(INTEGER_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.intWrapper();
			} else if(BIGINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.longWrapper();
			} else if(FLOAT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.floatWrapper();
			} else if(REAL_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.floatWrapper();
			} else if(DOUBLE_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.doubleWrapper();
			} else if(NUMERIC_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.bigDecimal();
			} else if(DECIMAL_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.bigDecimal();
			} else if(CHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.charWrapper();
			} else if(VARCHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.string();
			} else if(LONGVARCHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.string();
			} else if(DATE_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.date();
			} else if(TIME_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.time();
			} else if(TIMESTAMP_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.timestamp();
			} else if(BINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(VARBINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(LONGVARBINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(BLOB_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.blob();
			} else if(CLOB_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.clob();
			}
		} else {
			if(BIT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.booleanType();
			} else if(TINYINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteType();
			} else if(SMALLINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.shortType();
			} else if(INTEGER_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.intType();
			} else if(BIGINT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.longType();
			} else if(FLOAT_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.floatType();
			} else if(REAL_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.floatType();
			} else if(DOUBLE_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.doubleType();
			} else if(NUMERIC_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.bigDecimal();
			} else if(DECIMAL_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.bigDecimal();
			} else if(CHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.charType();
			} else if(VARCHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.string();
			} else if(LONGVARCHAR_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.string();
			} else if(DATE_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.date();
			} else if(TIME_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.time();
			} else if(TIMESTAMP_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.timestamp();
			} else if(BINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(VARBINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(LONGVARBINARY_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.byteArray();
			} else if(BLOB_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.blob();
			} else if(CLOB_TYPE.equalsIgnoreCase(sqlType)) {
				javaType = javaTypes.clob();
			}
		}
		
		return javaType;
	}
	
}
